<script template type="text/html">
    <link rel="stylesheet" href="{{ layui.setter.base }}style/login.css?v={{ layui.admin.v }}-1" media="all">
</script>


<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>layuiAdmin</h2>
            <p>layui 官方出品的单页面后台管理模板系统</p>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone"
                       for="LAY-user-login-cellphone"></label>
                <input class="layui-input" id="LAY-user-login-cellphone" lay-verify="phone" name="cellphone"
                       placeholder="手机"
                       type="text">
            </div>
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-xs7">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"
                               for="LAY-user-login-vercode"></label>
                        <input class="layui-input" id="LAY-user-login-vercode" lay-verify="required" name="vercode"
                               placeholder="验证码" type="text">
                    </div>
                    <div class="layui-col-xs5">
                        <div style="margin-left: 10px;">
                            <button class="layui-btn layui-btn-primary layui-btn-fluid" id="LAY-user-reg-getsmscode"
                                    type="button">获取验证码
                            </button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="LAY-user-login-password"></label>
                <input class="layui-input" id="LAY-user-login-password" lay-verify="pass" name="password"
                       placeholder="密码"
                       type="password">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="LAY-user-login-repass"></label>
                <input class="layui-input" id="LAY-user-login-repass" lay-verify="required" name="repass"
                       placeholder="确认密码"
                       type="password">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                       for="LAY-user-login-nickname"></label>
                <input class="layui-input" id="LAY-user-login-nickname" lay-verify="nickname" name="nickname"
                       placeholder="昵称"
                       type="text">
            </div>
            <div class="layui-form-item">
                <input checked lay-skin="primary" name="agreement" title="同意用户协议" type="checkbox">
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-filter="LAY-user-reg-submit" lay-submit>注 册</button>
            </div>
            <div class="layui-trans layui-form-item layadmin-user-login-other">
                <label>社交账号注册</label>
                <a href="javascript:"><i class="layui-icon layui-icon-login-qq"></i></a>
                <a href="javascript:"><i class="layui-icon layui-icon-login-wechat"></i></a>
                <a href="javascript:"><i class="layui-icon layui-icon-login-weibo"></i></a>

                <a class="layadmin-user-jump-change layadmin-link layui-hide-xs" lay-href="/user/login">用已有帐号登入</a>
                <a class="layadmin-user-jump-change layadmin-link layui-hide-sm layui-show-xs-inline-block"
                   lay-href="/user/login">登入</a>
            </div>
        </div>
    </div>

    <div class="layui-trans layadmin-user-login-footer">

        <p>© 2018 <a href="http://www.layui.com/" target="_blank">layui.com</a></p>
        <p>
            <span><a href="http://www.layui.com/admin/#get" target="_blank">获取授权</a></span>
            <span><a href="http://www.layui.com/admin/pro/" target="_blank">在线演示</a></span>
            <span><a href="http://www.layui.com/admin/" target="_blank">前往官网</a></span>
        </p>
    </div>

</div>

<script>
    layui.use(['admin', 'form', 'user'], function () {
        var $ = layui.$
            , setter = layui.setter
            , admin = layui.admin
            , form = layui.form
            , router = layui.router();

        form.render();

        //发送短信验证码
        admin.sendAuthCode({
            elem: '#LAY-user-reg-getsmscode'
            , elemPhone: '#LAY-user-login-cellphone'
            , elemVercode: '#LAY-user-login-vercode'
            , ajax: {
                url: './json/user/sms.js' //实际使用请改成服务端真实接口
            }
        });

        //提交
        form.on('submit(LAY-user-reg-submit)', function (obj) {
            var field = obj.field;

            //确认密码
            if (field.password !== field.repass) {
                return layer.msg('两次密码输入不一致');
            }

            //是否同意用户协议
            if (!field.agreement) {
                return layer.msg('你必须同意用户协议才能注册');
            }

            //请求接口
            admin.req({
                url: './json/user/reg.js' //实际使用请改成服务端真实接口
                , data: field
                , done: function (res) {
                    layer.msg('注册成功', {
                        offset: '15px'
                        , icon: 1
                        , time: 1000
                    }, function () {
                        location.hash = '/user/login'; //跳转到登入页
                    });
                }
            });

            return false;
        });
    });
</script>